<template>
  <div style="width: 100%;padding-top: 20px;">
    <!---->
    <el-form ref="dataForm" :rules="rules" :model="dataForm" auto-complete="off" status-icon label-position="left"
             label-width="150px" style="width: 50%; ">
      <el-form-item label="原密码" prop="oldPwd">
        <el-input v-model="dataForm.oldPwd" type="password" placeholder="请输入原密码"/>
      </el-form-item>
      <el-form-item label="新密码" prop="newPwd">
        <el-input v-model="dataForm.newPwd" type="password" auto-complete="off" placeholder="请输入新密码"/>
      </el-form-item>
      <el-form-item label="确认密码" prop="confirmPwd">
        <el-input v-model="dataForm.confirmPwd" type="password" auto-complete="off" placeholder="请输入确认密码"/>
      </el-form-item>
      <el-form-item style="margin-top:60px;">
        <el-button type="primary" @click="change">确定</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {doGet, doPost} from '@/api'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination

export default {
  name: 'realcheck',
  filters: { },
  components: {
    Pagination
  },
  data() {
    var validatePass2 = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请再次输入密码'))
      } else if (value !== this.dataForm.newPwd) {
        callback(new Error('两次输入密码不一致!'))
      } else {
        callback()
      }
    }
    var validatePass = (rule, value, callback) => {
      if (value.length < 6) {
        callback(new Error('密码长度应大于6'))
      } else {
        callback()
      }
    }
    return {
      list: [],
      unionnos: [],
      total1: 0,
      dataForm: {
        oldPwd: '',
        newPwd: '',
        confirmPwd: ''
      },
      rules: {
        oldPwd: [{ required: true, message: '旧密码不能为空', trigger: 'blur' }],
        newPwd: [
          { required: true, message: '新密码不能为空', trigger: 'blur' },
          { validator: validatePass, trigger: 'blur' }
        ],
        confirmPwd: [
          { required: true, message: '确认密码不能为空', trigger: 'blur' },
          { validator: validatePass2, trigger: 'blur' }
        ]
      },
      phoneText: '获取验证码',
      phoneloading: false,
      phoneDisabled: true,
    }
  },
  created() {
  },
  watch: { },
  methods: {
    change() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          doGet('chgpwd.html?', this.dataForm) .then(response => {
            /*this.cancel()*/
            this.$notify.success({
              title: '成功',
              message: '修改密码成功'
            })
          }).catch(response => {
            this.$notify.error({
              title: '失败',
              message: response.message
            })
          })
        }
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
</style>
